package com.tsingteng.cosfun.ui.mine.attent;

import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.bean.AttentFansbean;
import com.tsingteng.cosfun.callback.AppListener;
import com.tsingteng.cosfun.common.BroadcastManager;
import com.tsingteng.cosfun.common.Config;
import com.tsingteng.cosfun.common.Constant;
import com.tsingteng.cosfun.ui.mine.HomeMineFragment;
import com.tsingteng.cosfun.ui.mine.TerminalActivity;
import com.tsingteng.cosfun.utils.ImageUtils;

import de.hdodenhof.circleimageview.CircleImageView;


public class AttentAdapter extends BaseQuickAdapter<AttentFansbean.Data, BaseViewHolder> {

    private final AttentPresenter attentPresenter;

    public AttentAdapter(AttentPresenter attentPresenter) {
        super(R.layout.item_fans_adapter);
        this.attentPresenter = attentPresenter;

    }

    @Override
    protected void convert(BaseViewHolder helper, AttentFansbean.Data item) {
        if (item != null) {
            helper.setText(R.id.tv_fans_title, item.nickName + "");
            CircleImageView view = helper.getView(R.id.iv_fans_header);
            ImageUtils.LoadImage(mContext, item.image+ Config.YA_SUO_IMAGE_URL, view);
//            Glide.with(mContext).load(item.image).into(view);
        } else {
            helper.setText(R.id.tv_fans_title, "用户");
        }
        helper.setText(R.id.tv_fans_time, TextUtils.isEmpty(item.signature) ? "这家伙很懒，还没有写签名" : item.signature);
        TextView textView = helper.getView(R.id.tv_fans_follow);

//        if (item.followShip != null) {
//            textView.setText(item.followShip);
//        }

        Resources resources = mContext.getResources();
        textView.setVisibility(View.VISIBLE);
        switch (item.followType) {
            case 0:
                textView.setText("关注");
                textView.setBackground(resources.getDrawable(R.drawable.shape_bg_gray));
                textView.setTextColor(resources.getColor(R.color.black));
                break;
            case 1:
                textView.setBackground(resources.getDrawable(R.drawable.shape_bg_stoke_white));
                textView.setTextColor(resources.getColor(R.color.white));
                textView.setText("已关注");
                break;
            case 2:
                textView.setBackground(resources.getDrawable(R.drawable.shape_bg_lable));
                textView.setTextColor(resources.getColor(R.color.color_found));
                textView.setText("互相关注");
                break;
            case -1:
                textView.setVisibility(View.GONE);
                break;
        }

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if ("互相关注".equals(textView.getText()) || "已关注".equals(textView.getText())) {
                    onFocus(item.profileId+"::2");
                    attentPresenter.loginNoFollow(item.profileId + "", helper.getAdapterPosition());
                } else {
                    onFocus(item.profileId+"::1");
                    attentPresenter.loginFollowFans(item.profileId + "", helper.getAdapterPosition());
                }
            }
        });

        helper.getView(R.id.iv_fans_header).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int tag = 1;
//                Navigate.startUserHome(mContext,tag);
                Bundle bundle = new Bundle();
                bundle.putInt("tag", tag);
                bundle.putInt("user_id", item.profileId);
                TerminalActivity.showFragment(mContext, HomeMineFragment.class, bundle);
            }
        });
    }
    void onFocus(String focus){
        AppListener.OnFocusBackListener backListener = AppListener.getInstance().getFocusBackListener();
        if (null !=backListener){
            backListener.onFocusBack(focus);
        }
    }
}
